package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.CustomerDao;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.service.CustomerService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    private CustomerDao customerDao;

    ////客户列表分页（名称模糊查询）
    @Override
    public Map<String, Object> list(Integer page, Integer rows, String customerName) {
        //开启分页
        PageHelper.startPage(page,rows);
        Page<Customer> customerPage =customerDao.listSelect(customerName);
        Map<String, Object> map=new HashMap<>();
        map.put("rows",customerPage);
        map.put("total",customerPage.getTotal());
        return map;
    }

    //新增修改客户
    @Override
    public void save(Customer customer, String customerId) {
        if (customerId!=null){
            //修改
            customerDao.updateCustomer(customer);
        }else {
            //新增
            customerDao.saveCustomer(customer);
        }
    }

    //批量删除客户
    @Override
    public void delete(String[] ids) {
        for (String id : ids) {
            customerDao.deleteCustomer(id);
        }
    }

    //销售出库  客户下拉列表
    @Override
    public List<Customer> getComboboxList(String q) {
        return customerDao.getComboboxList(q);
    }
}
